function index_ = taskBiasLever_180Q(useASL, coarseAxes, numTrials, practiceTrials, overrideProbability, varargin)
% function index_ = taskBiasLever_180Q(useASL, coarseAxes, numTrials, practiceTrials, overrideProbability, varargin)
%
% Test the dXquest and lever pull motion disrimination task
%
%   index_ = taskEasyLever(varargin)
%
%   eye tracker for fixation
%   lpHID choices
%
%   varargin may contain e.g. {'rightAng', 45, ...} which determines
%   the dot direction associated with a rightward response.  The rest gets
%   passed to dXtask/set via rAdd.
%
%   index_ specifies the new instance in ROOT_STRUCT.dXtask

% copyright 2007 Benjamin Heasly University of Pennsylvania
% modified 2008 Benjamin Naecker University of Pennsylvania

% name for this task
name = mfilename;

%% Parse arguments
if nargin < 1 || isempty(useASL)
    useASL = true;
end

if nargin < 2 || isempty(coarseAxes)
    coarseAxes   = [];
    startTaskFcn = {};
    endTaskFcn   = {@copyQuestCoherences};
    showText     = false;
else
    coarseAxes   = coarseAxes(randperm(length(coarseAxes)));
    startTaskFcn = {@setupQuestForMotionAxis};
    endTaskFcn   = {};
    showText     = true;
end

if nargin < 3 || isempty(numTrials)
    numTrials = 90;
end
blockReps = ceil(numTrials/2);

if nargin < 4 || isempty(practiceTrials)
    practiceTrials = 0;
else
    practiceTrials = 2*(ceil(practiceTrials/2));
    blockReps      = blockReps + practiceTrials/2;
end
practiceValue = 100;

if nargin < 5 || isempty(overrideProbability)
    overrideProbability = 0;
end
overrideValue = 100;


% args to make statelist polymorphic
arg_statelist = {name(5:end), {'dXquest', 'dXtc', 'dXlr'}, useASL, showText};

arg_dXquest = { ...
    'stimRange',            [.5, 200], ...
    'stimValues',           1:100, ...
    'refStim',              20, ...
    'blankStim',            [], ...
    'guessStim',            20, ...
    'Tstd',                 9, ...
    'estimateType',         'mean', ...
    'psychParams',          [-1.5 3.5 .01 .5], ...
    'CIsignif',             .95, ...
    'CIcritdB',             2, ... % dB width defining converged CI
    'goPastConvergence',    true, ...
    'name',                 'dot_coh_92', ...
    'ptr',                  {{'dXdots', 1, 'coherence'}}, ...
    'showPlot',             false, ...
    'practiceTrials',       practiceTrials, ...
    'practiceValue',        practiceValue, ...
    'overrideProbability',  overrideProbability, ...
    'overrideValue',        overrideValue};
arg_dXtc = { ...
    'name',     'high_coh_dot_dir', ...
    'values',	[180, 0], ...
    'ptr',      {{'dXdots', 1, 'direction'}}};

arg_dXlr = { ...
    'ptr',      {{'dXdots', 1, 'direction'}}};

% {'group', reuse, set now, set always}
static = {'current', true, true, false};
reswap = {'current', false, true, false};

bta = bias_task_args;
index_ = rAdd('dXtask', 1, {'root', false, true, false}, ...
    'name',         name(5:end), ...
    'userData',     coarseAxes, ...
    'startTaskFcn', startTaskFcn, ...
    'endTaskFcn',   endTaskFcn, ...
    'blockReps',    blockReps, ...
    'bgColor',      [0,0,0], ...
    'helpers',      { ...
    'dXquest',              1,  reswap, arg_dXquest; ...
    'dXtc',                 1,  reswap, arg_dXtc; ...
    'dXlr',                 1,  static, arg_dXlr; ...
    'gXbias_hardware',      1,  true,   {useASL}; ...
    'gXbias_graphics',      1,  true,	{}; ...
    'gXbias_statelist',     1,  false,	arg_statelist}, ...
    bta{:}, varargin{:});